package com.atguigu.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @auther zzyy
 * @create 2020-02-24 16:26
 */
@RestController
@Slf4j
public class FlowLimitController {
    @GetMapping("/testA")
    public String testA() {
        return "------testA1";
    }
    @GetMapping("/testB")
    public String testB() {
        try {
            Thread.sleep(999);
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("sss");
        }
        log.info(Thread.currentThread().getName() + "\t" + "...testB");
        return "------testB1";
    }
    /**
     * 热点key限流
     */
    @GetMapping("/testHotKey")
    // @SentinelResource(value = "testHotKey", 这个名字是唯一的 testHotKey 这个就是资源名称
    @SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1, @RequestParam(value = "p2", required = false) String p2) {
        //int age = 10/0;
        return "------testHotKey";
    }
    //兜底方法
    public String deal_testHotKey(String p1, String p2, BlockException exception) {
        return "------deal_testHotKey,o(╥﹏╥)o";
    }
}